﻿<%@ WebHandler Language="C#" Class="CheckSignin" %>

using System;
using System.Web;
using System.Linq;

public class CheckSignin : IHttpHandler {
    security baomat = new security();
    public void ProcessRequest (HttpContext context) {
        string statusText = "";
        try
        {
            if (string.IsNullOrEmpty(context.Request.QueryString["uid"]) || string.IsNullOrEmpty(context.Request.QueryString["pass"]))
            {
                statusText = "-1";
            }
            else
            {
                string username = context.Request.QueryString["uid"];
                string pass = baomat.EncryptPWD(context.Request.QueryString["pass"]);
                using (Up1VNDataContext dc = new Up1VNDataContext())
                {
                    var query = from o in dc.Users where o.Users_Name == username && o.Users_Password == pass select o;
                    if (query.Count() > 0)
                    {
                        if (query.Single().Users_IsEnable == 1)
                        {
                            HttpCookie cookie = new HttpCookie("userinfo");
                            cookie["username"] = username;
                            cookie.Expires = DateTime.Now.AddDays(1);
                            context.Response.Cookies.Add(cookie);
                            statusText = "1";
                        }
                        else
                        {
                            statusText = "2";
                        }
                    }
                    else
                    {
                        statusText = "0";
                    }
                }
            }
        }
        catch (Exception)
        {
            statusText = "-1";
        }
        context.Response.Write(statusText);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}